package company.bigo_F;

import java.util.ArrayList;
import java.util.List;

public class BiGo1 {

    public static void main(String[] args) {
        System.out.println(helper(new int[]{1, 3, -1, -1, 5, 3, 6, 7}, 3));
    }

    private static List<Integer> helper(int[] nums, int k) {
        List<Integer> result = new ArrayList<>();
        int max = 0;
        for (int i = 0; i < k; i++) {
            max = Math.max(max, nums[i]);
        }
        result.add(max);
        int n = nums.length;
        for (int i = k; i < n; i++) {
            //更新max
            if (nums[i] > max)
                max = nums[i];
            //max出队后重新选举最大值
            else if (nums[i - k] == max) {
                //重新寻找max
                for (int j = i - k + 1; j <= i; j++) {
                    max = nums[j];
                }
            }
            result.add(max);
        }
        return result;
    }
}
